home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / ip / ppp / mac / macppp1.1.3-src.hqx / MacPPP1.1.3-src / lap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-08  |  5.4 KB  |  202 lines

  1. /*
  2.  *  lap.c
  3.  *
  4.  * This module contains the MacTCP Lap interface routines.
  5.  *
  6.  * Copyright 1992-1993 Merit Network, Inc. and The Regents of the
  7.  *  University of Michigan.  Usage of this source code is restricted
  8.  *  to non-profit, non-commercial purposes.  The source is provided
  9.  *  "as-is", without warranty.
  10.  *
  11.  */
  12. #include "ppp.h"
  13. #include <Folders.h>
  14. #include <GestaltEqu.h>
  15. /*
  16. *   PPPAttachPH
  17. *    MacTCP passes us the address of the IP protocol handler, which we must
  18. *    call after receiving an IP packet over the serial line.
  19. *    Called at application level or system task time.
  20. */
  21.  
  22. OSErr PPPAttachPH(LapInfo *lap, voidProcPtr ptr) {
  23.     lap->ip_ph = ptr;    /* save address of routine to call on receive done */
  24.     return (noErr);
  25. }
  26.  
  27. /*  PPPClose
  28. *    Called by MacTCP to close the LAP.
  29. *    Called at application level or system task time.
  30. */
  31. OSErr PPPClose(LapInfo * lap) {
  32.     link_close(lap);        /* close the link */
  33.     fsm_close(&(lap->ppp_fsm[Lcp]));    /* send close event to LCP */
  34.     fsm_close(&(lap->ppp_fsm[IPcp]));    /* close IPcp to put it back in Initial state */
  35. }
  36.  
  37. /*
  38. *   PPPConfigure
  39. *    Called by MacTCP driver after LAP initialization.  This routine 
  40. *    fills in the IP address and netmask.
  41. */
  42.  
  43. void PPPConfigure(LapInfo *lap) {
  44.     if (lap->ppp_fsm[IPcp].state == fsmOPENED) { /* check if IPCP is opened */
  45.         /* return IP address negotiated by IPCP to MacTCP */
  46.         lap->cur_ip_addr = lap->ipcp_i.local.work.ipcp_option.address;
  47.     
  48.         /*  set netmask to something resonable */
  49.         if (lap->cur_ip_addr & 0xC0000000)
  50.             lap->cur_net_mask = 0xffffff00;
  51.         else if (lap->cur_ip_addr & 0x80000000)
  52.             lap->cur_net_mask = 0xffff0000;
  53.         else
  54.             lap->cur_net_mask = 0xff000000;
  55.         return;
  56.     }
  57.     /* lap is closed, so try to re-open */
  58.     PPP_DEBUG_CHECKS("\pConfigure on closed lap");
  59.     if (lap->transProc != nil) {
  60.         (*(lap->transProc))(TransitionOpen);    /* try reopening lap */
  61.     }
  62. }
  63.  
  64. /*
  65. *   PPPControl
  66. *    This routine is never called by the current version of MacTCP (1.1.1)
  67. */
  68.  
  69. OSErr PPPControl(LapInfo * lap) {
  70.     return (noErr);
  71. }
  72. /*
  73. *   PPPDetachPH
  74. *    Called when MacTCP driver is closing.  This routine releases binding
  75. *    to the IP packet reception routine.
  76. */
  77. OSErr PPPDetachPH(LapInfo *lap) {
  78.     lap->ip_ph = nil;
  79.     return (noErr);
  80. }
  81.  
  82. /*
  83. *   PPPFault
  84. *    MacTCP detected problem in communication
  85. */
  86. void PPPFault(LapInfo *lap, ip_addr lnd) {
  87.     lap->faults++;
  88. }
  89.  
  90. /*
  91. *   PPPFindGW
  92. *   The concept of a gateway isn't relevent for a point-to-point link,
  93. *   but we need to provide an address to MacTCP.
  94. */
  95. void PPPFindGW(struct LapInfo *lap)
  96. {
  97.     /* Just use our IP address as the gateway address */
  98.     lap->lc.dfl_gateway_addr = lap->cur_ip_addr;
  99.     return;
  100. }
  101. /*
  102. *   PPPInit
  103. *    Called when the MacTCP driver is opened.  We attempt to open the
  104. *   PPP session at this point, by sending an open event to the IPCP
  105. *   protocol.
  106. */
  107. OSErr PPPInit(LapInfo *lap, longProcPtr transitionProc) {
  108.  
  109.     if (lap->ppp_flags & CLOSE_PPP) {
  110.         lap->ppp_flags &= ~CLOSE_PPP;
  111.         lap->transProc = nil;
  112.         return -1;
  113.     }
  114.     if (lap->ppp_flags & (ECHO_FAIL | IDLE_TIMEOUT)) {
  115.         link_open(lap);        /* handle special cases */
  116.         lap->ppp_flags &= ~(ECHO_FAIL | IDLE_TIMEOUT);
  117.     } else
  118.         fsm_open( &(lap->ppp_fsm[IPcp]) ); /* try opening IPCP */
  119.     if (lap->ppp_fsm[IPcp].state != fsmOPENED) { /* check if IPCP is up */
  120.         lap->transProc = nil;    /* reset tranproc pointer */
  121.         return -1;        /* indicate init failed to MacTCP */
  122.     }
  123.     if ( transitionProc != nil ) {    /* if this is first call */
  124.         lap->ip_ph = nil;                /* reset packet handler pointer */
  125.         lap->savProc = transitionProc;    /* set pointer to transition proc */
  126.     }
  127.     lap->transProc = lap->savProc;    /* refresh transition proc pointer */
  128.     return noErr;        /* PPP is up */
  129. }
  130. /*
  131. *   PPPOpen
  132. *    Not called by current version of MacTCP (1.1.1)
  133. */
  134. OSErr PPPOpen(LapInfo *lap) {
  135.     return (noErr);
  136. }
  137. /*
  138. *   PPPProbe
  139. *    Used only for dynamic addressing.  Not useful for MacPPP.
  140. */
  141. Boolean PPPProbe(LapInfo *lap, ip_addr addr) {
  142.     return (false);
  143. }
  144. /*
  145. *   PPPRegister
  146. *    Assume the remote end gave us a good IP address.
  147. */
  148. Boolean PPPRegister(LapInfo *lap) {
  149.     lap->addressConflict = FALSE;
  150.     return (1);
  151. }
  152. /*
  153. *   PPPStatistics
  154. *    Called by MacTCP to acquire link speed information and for
  155. *    network management.  Decision on protocol timeouts and usable MTU
  156. *    are made with the values returned by this call.
  157. */
  158. OSErr PPPStatistics(struct LapInfo *lap, struct LapStats *statsPtr) {
  159.     statsPtr->ifMaxMTU = lap->outMaxPacketSize;
  160.     statsPtr->ifSpeed = (unsigned long) lap->configdata.baudrate;
  161.     statsPtr->ifPhyAddrLength = 0;
  162.     statsPtr->ifPhysicalAddress = nil;
  163.     return (noErr);
  164. }
  165. /*
  166. *   PPPUnload
  167. *    Called by MacTCP driver to release the memory held by the
  168. *    LAP.
  169. */
  170. void PPPUnload(struct LapInfo *lap) {
  171.     if (lap->ppp_phase != pppDEAD)
  172.         link_close(lap);    /* close the link */
  173.     SetLAPPtr(nil);            /* set lap pointer to nil */
  174.     DisposPtr((Ptr) lap);    /* dispose of memory */
  175.     return;
  176. }
  177. /*
  178. *   PPPWrite
  179. *    MacTCP calls this routine to transmit an IP packet on our link.  
  180. *    The write requests are queued for transmission.
  181. */
  182. void IOCompleted(LapInfo *, struct ipbuf *);
  183.  
  184. OSErr PPPWrite(LapInfo *lap, ip_addr addr, struct ipbuf *ipb) {
  185.  
  186.     lap->idle_timer = 0;    /* clear idle timer */
  187.     if (lap->ppp_fsm[IPcp].state != fsmOPENED) {
  188.         PPP_DEBUG_CHECKS("\pPPPWrite: IPcp not opened");
  189.         IOCompleted(lap, ipb);        /* fake the completion routine */
  190.         /* (*(lap->transProc))(TransitionOpen); */ /* signal open */
  191.         lap->OutError++;
  192.         return (noErr);        /* return no error */
  193.     }
  194.  
  195.     /* save ptr to LapInfo for IP */
  196.     ipb->lap = lap;
  197.     
  198.     /* try to get a free transmit queue element */
  199.     return(QueueFrame(lap, nil, ipb));
  200. }
  201.  
  202.